package pl.softech.logger;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.LogManager;

public class LoggerConfig {
    
    private final Properties props;

    public LoggerConfig() {
        props = new Properties();
        init();
        loadConfig();
    }

    private void init() {
        props.put("handlers", "java.util.logging.ConsoleHandler");
        props.put(".level", "INFO");
        props.put("pl.level", "ALL");
        props.put("java.util.logging.ConsoleHandler.level", "ALL");
        props.put("java.util.logging.ConsoleHandler.formatter", MyFormatter.class.getName());
    }
    
    private void loadConfig() {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            props.store(out, "");
            InputStream in = new ByteArrayInputStream(out.toByteArray());
            LogManager.getLogManager().readConfiguration(in);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
